package myqueue;

import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class MyQueue {
    class ListNode{
        public int val;
        public ListNode next;
        public ListNode pre;
        public ListNode(int val) {
            this.val = val;
        }
    }
    private ListNode head;
    private ListNode last;
    private int size;
    public int size(){
        return size;
    }
    public boolean isEmpty(){
        return size==0;
    }
    public void offer(int value){
        ListNode node =new ListNode(value);
        if (head==null){
            head=last=node;
        }else {
            last.next=node;
            node.pre=last;
            last=last.next;
        }
        size++;
    }
    public int poll(){
        if (isEmpty()){
         return -1;
        }
        int ret=0;
        if(head.next==null){
            ret =head.val;
            head=last=null;
        }else {
            ret =head.val;
            head=head.next;
            head.pre=null;
        }
        size--;
        return ret;
    }
    public int peek(){
        if (isEmpty()){
            return -1;
        }
        return head.val;
    }
}
